﻿using Microsoft.AspNetCore.Mvc;
using Shop.Core.Share;
using Shop.IServices;
using Shop.Model.Dto.User;
using Shop.Model.View.Use;

namespace Shop.WebApi.Controllers
{
    /// <summary>
    /// 地址服务
    /// </summary>
    [ApiController]
    [Route("Api/[controller]")]
    public class AddressController : ShopControllerBase
    {
        private readonly IAddressAppService _addressService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="addressService"></param>
        public AddressController(IAddressAppService addressService)
        {
            _addressService = addressService;
        }

        /// <summary>
        /// 添加用户收货地址
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("Add")]
        public async Task<AppResult<bool>> AddUserHarvestAddress(AddressAddDto input)
        {
            return await _addressService.CreateAsync( input);
        }

        /// <summary>
        /// 修改用户收货地址
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("Edit")]
        public async Task<AppResult<bool>> UpdateUserHarvestAddress(AddressModifyDto input)
        {
            return await _addressService.UpdateAsync(input);
        }

        /// <summary>
        /// 删除用户收货地址
        /// </summary>
        /// <param name="Input"></param>
        /// <returns></returns>
        [HttpPost("Delete")]
        public async Task<AppResult<bool>> DeleteAsync([FromBody] SimpleDto<long> Input)
        {
            return await _addressService.DeleteAsync(Input.Value);
        }

        /// <summary>
        /// 获取用户收货地址列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("List")]
        public async Task<AppResult<List<AddressVo>>> GetlistAsync()
        {
            return await _addressService.ListAsync();

        }
    }
}
